import 'package:flutter/material.dart';
import 'package:test01/pages/category_info/all_item.dart';
import 'package:test01/pages/login/login.dart';
import 'package:test01/pages/login/register.dart';
import 'package:test01/pages/main/main.dart';
import 'package:test01/pages/my/change_info.dart';
import 'package:test01/pages/my/crop_image_route.dart';
import 'package:test01/pages/search/search.dart';
import 'package:test01/pages/travel_info/travel.dart';

var router = {
  //配置路由路径
  '/': (context, {arguments}) => const MainScreen(),//使用arguments传递参数
  '/travel': (context, {arguments}) => TravelScreen(arguments),
  '/itemInfo': (context, {arguments}) => AllItemScreen(arguments),
  '/search': (context, {arguments}) => const SearchScreen(),
  '/login': (context, {arguments}) => const LoginScreen(),
  '/register': (context, {arguments}) => const RegisterScreen(),
  '/changeInfo': (context, {arguments}) => const ChangeInfoScreen(),
  "/cropImage": (context, {arguments}) => CropImageRoute(arguments: arguments,)
};

// ignore: top_level_function_literal_block
var onGenerateRoute = (RouteSettings settings) {
  //onGenerateRoute配置
  final String? name = settings.name;
  final Function pageContentBuilder = router[name] as Function;
  // ignore: unnecessary_null_comparison
  if (pageContentBuilder != null) {
    if (settings.arguments != null) {
      final Route route = MaterialPageRoute(
          builder: (context) =>
              pageContentBuilder(context, arguments: settings.arguments));
      return route;
    } else {
      final Route route =
          MaterialPageRoute(builder: (context) => pageContentBuilder(context));
      return route;
    }
  }
};
